<script>
import init from "@/libs/init";
import {commonApi} from "@/api";

export default {
  onLaunch(args) {
    console.log('================================================ start ========================================================================')
    plus.ad.setPrivacyConfig({
      "isAdult": true,
      "isCanUsePhoneState": false,
      "isCanUseStorage": true,
      "isCanUseLocation": true,
      "isCanUseWifiState": true,
      "isCanGetInstallAppList": false,
      "isCanGetRunningApps": false,
      "isCanGetMacAddress": false,
      "isCanGetAndroidId": true,
      "isCanGetOAID": true,
      "isCanGetIP":false,
      "isGDTAgreeStrategy":true
    })
    this.start()
  },
  onShow(args) {
    init.initQuery(args)
    console.log('App Show')
  },
  onHide() {
    console.log('App Hide')
  },
  methods: {
    async start() {
      await init.initEnv()
      console.log('App launch start')
      uni.getNetworkType({
        success: (res) => {
          console.log('network', res.networkType)
          if (res.networkType === 'none') {
            const init = (res) => {
              console.log('onNetworkStatusChange', res);
              if (res.isConnected) {
                uni.offNetworkStatusChange(init)
                //请求接口
                this.init()
              }
            }

            uni.onNetworkStatusChange(init);
            commonApi.test()
          } else {
            this.init()
          }
        }
      })
    },
    async init() {
      try {
        await init.initData()
      } catch (e) {
        console.log(e)
      }

      console.log('App onLaunch')
      // uni.getPushClientId({
      //   success: (res) => {
      //     console.log('getPushClientId', res.cid);
      //   },
      //   fail(err) {
      //     console.log('getPushClientId', err)
      //   }
      // })
      // uni.onPushMessage((res) => {
      //   console.log('onPushMessage', res)
      // })
    },
    getPhoneNumber({params, success, fail}) {
      const {iv, encryptedData} = params;
      // ...
      // 开发者服务端解密 encryptedData，得到手机号
      // ...
      const result = {
        phoneNumber: '13580006666',
      }
      // 回调前端模板
      success(result)
    },
    getThemeConfig() {
      console.log('xxx', arguments)
      return {
        borderRadius: '8rpx',  // string
        backgroundColor: '#FE2C55',  // string
        fontColor: '#ffffff', // string
      }
    }
  }
}
</script>

<style lang="scss">
// #ifndef APP-PLUS-NVUE
@import './styles/common.scss';

.product-detail-container {
  pay-button, .buy-btn {
    width: 300rpx;
    height: 96rpx;
  }
}

image {
  will-change: transform
}

::-webkit-scrollbar {
  display: none;
}

button::after {
  border: none;
}

body {
  font-size: 14px;
  background-color: #f9f9f9;
}

.m-r-30 {
  margin-right: 30rpx;
}

.m-r-20 {
  margin-right: 20rpx;
}

.flex {
  display: flex;

  &.v {
    flex-direction: column;

    &.right {
      align-items: flex-end;
    }

    &.vc {
      justify-content: center;
    }

    &.hc {
      align-items: center;
    }
  }

  &.h {
    &.right {
      justify-content: flex-end;
    }

    &.vc {
      align-items: center;
    }

    &.hc {
      justify-content: center;
    }
  }
}

.f1 {
  flex: 1;
}

.main-input-wrapper {
  background-color: #f6f6f6;
  height: 96rpx;
  border-radius: 48rpx;
  margin-top: 40rpx;
  align-items: center;
  display: flex;
  padding: 0 48rpx;

  &:first-child {
    margin-top: 0;
  }

  input {
    flex: 1;
  }
}

.custom-btn {
  height: 96rpx;
  background-color: #f6f6f6;
  border-radius: 48rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 32rpx;

  &.disable {
    color: #fff;
    background-color: #d9d9d9;
  }

  &.primary {
    background-color: #3073f6;
    color: #fff;
  }
}


.group {
  background-color: #fff;
  margin-bottom: 30rpx;

  .divider {
    background-color: #e7e7e7;
    height: 1px;
    margin: 0 30rpx;
  }
}

.row-container {
  display: flex;
  background-color: #fff;
  height: 134rpx;
  align-items: center;
  padding: 0 30rpx;

  .label {
    flex: 1;
    font-size: 30rpx;
  }

  .sub-label {
    color: #999;
    margin-right: 20rpx;

    &.blue {
      color: #3073f6;
    }
  }

  .arrow {
    width: 20rpx;
    height: 20rpx;
    transform: rotate(180deg);
  }

  .avatar {
    width: 80rpx;
    height: 80rpx;
    margin-right: 20rpx;
    border-radius: 40rpx;
  }

  .btn-title {
    flex: 1;
    text-align: center;
    color: #3073f6;
  }
}

.dialog {
  padding: 32rpx;
  border-radius: 24rpx;

  background-color: #fff;
  width: 590rpx;
  box-sizing: border-box;

  .title {
    font-size: 34rpx;
    font-weight: 500;
    text-align: center;
    margin-top: 12rpx;
    margin-bottom: 10rpx;
  }

  .content {
    color: #878787;
    line-height: 2em;
    margin: 8rpx;
  }

  .footer {
    display: flex;
    margin-top: 40rpx;

    .btn {
      flex: 1;
      height: 82rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 30rpx;
      background-color: #ededed;
      border-radius: 42rpx;
      margin-left: 28rpx;

      &:first-child {
        margin-left: 0;
      }

      &.primary {
        background-color: #3073f6;
        color: #fff;
      }
    }
  }
}

// #endif
</style>
